package com.zhengqiangblog.blog.service;

import java.util.Date;

import org.apache.log4j.Logger;

import com.zhengqiangblog.blog.cache.AdminAccountCache;
import com.zhengqiangblog.blog.model.AdminAccount;
import com.zhengqiangblog.core.ApplicationContext;

public class AdminAccountService {

	private static final Logger logger = Logger.getLogger(AdminAccountService.class);

	private AdminAccountCache adminAccountCache = ApplicationContext.get(AdminAccountCache.class);

	public AdminAccountService() {
		logger.info("AdminAccountService initializing...");
	}

	public AdminAccount login(String login, String password) throws Exception {
		AdminAccount adminAccount = adminAccountCache.login(login, password);
		if (adminAccount != null) {
			adminAccountCache.updateLastLoginDate(adminAccount.getId(), new Date());
			logger.info("admin login success: " + login);
		} else {
			logger.info("admin login error: " + login);
		}
		return adminAccount;
	}

}
